<?php
if (!defined("_INDEX")) { header("Location: /"); die; }

$what = "friends";
switch ($route->getAdminId())
{
	case "index": 
	case "friends":		$what = "friends"; break;
	case "comments":	$what = "comments"; break;
	case "topics":		$what = "topics"; break;
}

require_once COORDINATOR.DS."head.php";
?>
<script type='text/javascript'>
$(document).ready(function(){
	$("#searchByFriends").keyup(function(){
		$(".thead").show();
		$(".report_head").show();
		$(".reports .email").each(function(i){
			
			if ($(this).html().search($("#searchByFriends").val()) == -1)
				$(this).parent().hide();
			else
				$(this).parent().show();
		});
		/* $("tr:not(.thead):not(.report_head)").each(function(i,a){
			if ($(this).css('display') == 'none')
				$(this).prev(".thead").hide().prev(".report_head").hide();
		}); */
	});
	$("#searchByComments").keyup(function(){
		$(".thead").show();
		$(".reports .comment").each(function(i){
			
			if ($(this).html().search($("#searchByComments").val()) == -1)
				$(this).parent().hide();
			else
				$(this).parent().show();
		});
		/* $("tr:not(.thead):not(.report_head)").each(function(i,a){
			if ($(this).css('display') == 'none')
				$(this).prev(".thead").hide();
		}); */
	});
	$("#searchByTopics").keyup(function(){
		$(".thead").show();
		$(".reports .topic").each(function(i){
			
			if ($(this).html().search($("#searchByTopics").val()) == -1)
				$(this).parent().hide();
			else
				$(this).parent().show();
		});
		/* $("tr:not(.thead):not(.report_head)").each(function(i,a){
			if ($(this).css('display') == 'none')
				$(this).prev(".thead").hide();
		}); */
	});
})
</script><?php
if ($what == "friends")
{
	?><a href='/coordinator/reports/look/friends' class="submenu_button submenu_button_active" >Друзья</a>
	<a href='/coordinator/reports/look/comments' class="submenu_button">Комментарии</a>
	<a href='/coordinator/reports/look/topics' class="submenu_button">Статьи</a><br /><br /><br />
	<div class='search'>
		Поиск по пользователю: <input type='text' id='searchByFriends' /><br /><br />
	</div>
	<table class='reports'><?php
		$reports = $db->getTable("select `R`.`report_id`,`R`.`user_id`,`R`.`date` as `r_date`,`C`.`name` as `c_name`,`A`.`name` as `a_name`,`F`.*
								from `reports` as `R`,`friends` as `F`,`cities` as `C`,`areas` as `A`
								where `R`.`user_id` = '".$user->getUserId()."' and `R`.`report_id` = `F`.`report_id` and `F`.`city_id`=`C`.`city_id` and `F`.`area_id`=`A`.`area_id` order by `R`.`report_id` desc,`date` desc");
		$rep = 0;
		
		foreach ($reports as $report)
		{
			if ($rep != $report['report_id'])
			{
				echo "<tr class='report_head'><td colspan='12'>Отчет от ".date("d.m.Y H:i",$report['r_date'])."</td></tr>";
				echo "<tr class='thead'><td>Пользователь</td><td>Дата</td><td>Пол</td><td>Воз.</td><td>Адрес</td><td>Описание</td><td class='comment_td'>Комментарий</td><td align='right'>Действия</td></tr>";
				$rep = $report['report_id'];
			}
			echo "<tr>";
			echo "<td class='email'>".$report['login']."@".$report['domain'].".ru <br />($report[sname] $report[name] $report[tname])</td>";
			echo "<td>".date("d.m.Y H:i",$report['date'])."</td>";
			echo "<td>".($report['sex'] == 'male' ? "Муж." : ($report['sex'] == 'female' ? "Жен." : "Неиз.")) ."</td>";
			echo "<td style='width:60px'>".($report['age'] != 0 ? wordEnding($report['age'],"год","года","лет") : "неиз.")."</td>";
			echo "<td style='width:160px;'>$report[c_name]<br />($report[a_name] р-н)<br />$report[street]</td>";
			echo "<td>".$report['description']."</td>";
			echo "<td align='center'><div class='comment ".($report['comment'] == "" ? "red" : "green")."'></div></td>";
			echo "<td><a class='send right' href='/coordinator/reports/edit/friends/".$report['friend_id']."'>Редактировать</a><br />".
				"<a class='delete right' href='/coordinator/reports/delete/friends/".$report['friend_id']."'>Удалить</a></td>";
			echo "</tr>";
		}
	?></table>
	<?php
}
elseif ($what == "comments")
{
	?><a href='/coordinator/reports/look/friends' class="submenu_button">Друзья</a>
	<a href='/coordinator/reports/look/comments' class="submenu_button submenu_button_active">Комментарии</a>
	<a href='/coordinator/reports/look/topics' class="submenu_button">Статьи</a><br /><br /><br />
	<div class='search'>
		Поиск: <input type='text' id='searchByComments' /><br /><br />
	</div>
	<table class='reports'><?php
		$reports = $db->getTable("select `R`.`report_id`,`R`.`user_id`,`R`.`date` as `r_date`,`Co`.*
								from `reports` as `R`,`comments` as `Co`
								where `R`.`user_id` = '".$user->getUserId()."' and `R`.`report_id` = `Co`.`report_id` order by `R`.`report_id` desc,`R`.`date` desc");
		$rep = 0;
		
		foreach ($reports as $report)
		{
			if ($rep != $report['report_id'])
			{
				echo "<tr class='report_head'><td colspan='12'>Отчет от ".date("d.m.Y H:i",$report['r_date'])."</td></tr>";
				echo "<tr class='thead'><td>Информация</td><td class='comment_td'>Комментарий</td><td align='right'>Действия</td></tr>";
				$rep = $report['report_id'];
			}
			echo "<tr>";
			echo "<td class='comment'><span class='bold'>Пользователь</span>: <a href='$report[friend_id]'>$report[friend_id]</a><br />
			<span class='bold'>Ссылка</span>: <a href='$report[link]'>$report[link]</a><br />
			<span class='bold'>Комментарий</span>: $report[comment]</td>";
			echo "<td align='center'><div class='comment ".($report['ucomment'] == "" ? "red" : "green")."'></div></td>";
			echo "<td class='actions'><a class='send right' href='/coordinator/reports/edit/comments/".$report['comment_id']."'>Редактировать</a><br />".
				"<a class='delete right' href='/coordinator/reports/delete/comments/".$report['comment_id']."'>Удалить</a></td>";
			echo "</tr>";
		}
	?></table><?php
}
elseif ($what == "topics")
{
	?><a href='/coordinator/reports/look/friends' class="submenu_button">Друзья</a>
	<a href='/coordinator/reports/look/comments' class="submenu_button">Комментарии</a>
	<a href='/coordinator/reports/look/topics' class="submenu_button submenu_button_active">Статьи</a><br /><br /><br />
	<div class='search'>
		Поиск: <input type='text' id='searchByTopics' /><br /><br />
	</div>
	<table class='reports'><?php
		$reports = $db->getTable("select `R`.`report_id`,`R`.`user_id`,`R`.`date` as `r_date`,`T`.*
								from `reports` as `R`,`topics` as `T`
								where `R`.`user_id` = '".$user->getUserId()."' and `R`.`report_id` = `T`.`report_id` order by `R`.`report_id` desc,`R`.`date` desc");
		$rep = 0;
		
		foreach ($reports as $report)
		{
			if ($rep != $report['report_id'])
			{
				echo "<tr class='report_head'><td colspan='12'>Отчет от ".date("d.m.Y H:i",$report['r_date'])."</td></tr>";
				echo "<tr class='thead'><td>Информация</td><td class='comment_td'>Комментарий</td><td align='right'>Действия</td></tr>";
				$rep = $report['report_id'];
			}
			echo "<tr>";
			echo "<td class='topic'><span class='bold'>Пользователь</span>: <a href='$report[friend_id]'>$report[friend_id]</a><br />
			<span class='bold'>Сссылка на статью</span>: <a href='$report[link]'>$report[link]</a><br />
			<span class='bold'>Название</span>: $report[title]<br />
			<span class='bold'>Дата создания</span>: ".date("d.m.Y",$report['date'])."<br />
			<span class='bold'>Описание</span>: $report[description]</td>";
			echo "<td align='center'><div class='comment ".($report['comment'] == "" ? "red" : "green")."'></div></td>";
			echo "<td><a class='send right' href='/coordinator/reports/edit/topics/".$report['topic_id']."'>Редактировать</a><br />".
				"<a class='delete right' href='/coordinator/reports/delete/topics/".$report['topic_id']."'>Удалить</a></td>";
			echo "</tr>";
		}
	?></table><?php
}

require_once COORDINATOR.DS."footer.php";
?>